package ds.recursive;

public class TowersII {

	private static int N;
	
	private static void printBlank(int count)
	{
		for(int i=0;i<count;i++)
		{
			System.out.print("  ");
		}
	}
	
	private static void doTowers(int topN, char from, char inter, char to)
	{
		printBlank(N-topN);
		System.out.println("Start(" + topN + " Disks): from " + from + " to " + to);
		if(topN == 1) // when n=1, move directly
		{
			printBlank(N-topN+1);
			System.out.println("Base Case: Move Disk 1 from " + from + " to " + to);			
		}
		else
		{
			
			
			doTowers(topN-1,from,to,inter); // (n-1)from --> inter
			
			printBlank(N-topN+1);
			System.out.println("Move Buttom Disk " + topN + " from " + from + " to " + to);
			                                // move the 'n' to destination
			
			doTowers(topN-1,inter,from,to); // (n-1)inter --> to
			
		}
		printBlank(N-topN);
		System.out.println("Returned(" + topN + " Disks): from " + from + " to " + to);
	}
	
	public static void doTowers(int n)
	{
		N = n;
		doTowers(n, 'a', 'b', 'c');
	}
}

class TowersAppII {
	public static void main(String[] args){
		TowersII.doTowers(5);
	}
}
